package com.feiyun.exception;

import static com.feiyun.util.ResponseUtil.exception;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import com.feiyun.model.dto.ResultVO;

/**
 * Function Desc: ExceptionHandler
 *
 * @author yan
 * @since 2023/3/20 22:38
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {


    @ExceptionHandler(ServiceException.class)
    @ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
    public ResponseEntity<ResultVO<String>> handleServiceException(ServiceException exception) {
        log.error(
                "ServiceException has occurred, code:{} msg:{}",
                exception.getCode(),
                exception.getMsg());
        return exception(exception.getCode(), exception.getMsg(), null);
    }
}
